using System;

namespace BlobSim
{
    class RotationSpeedDampenerPercentual : RotationSpeedDampener
    {
        private const float DefaultPercentPerSecond = 0.5f;

        private float _percentPerSecond = DefaultPercentPerSecond;

        public float PercentPerSecond
        {
            get { return _percentPerSecond; }
            set
            {
                if (value < 0 || value > 1.0)
                    throw new ArgumentOutOfRangeException("value", "value must be between 0 and 1");

                _percentPerSecond = value;
            }
        }

        public override float GetNewSpeed(float speed, TimeSpan delta)
        {
            if (speed < 0)
                throw new ArgumentOutOfRangeException("speed", "value must be a positive number");

            var newSpeed = speed * (1.0f - _percentPerSecond * (float)delta.TotalSeconds);

            if (newSpeed > 0.0f && ShouldStop(newSpeed)) return 0.0f;

            return newSpeed;
        }
    }
}
